Out: Monday, November 17, 2014
Due: Monday, December 1, 2014 at 600pm local time.
THIS IS THE LAST PROBLEM SET. CODEWALKS FOR THIS PROBLEM SET WILL BE DECEMBER 2-5. THIS WILL BE YOUR LAST OBLIGATION IN THIS COURSE.
The goal of this problem set is to give you practice with stateful classes, and pulling and pushing information. It is also intended to give you practice with reusing code from previous problem sets.
Please restrict yourself to the language features discussed in class. You may use state. You may not use inheritance.
Otherwise, the deliverables and instructions for this problem set are the same as for Problem Set 09.
(define StatefulWorld<%> (interface () ;; -> Void ;; EFFECT: updates this World StatefulWorld<%> to the state that it should be in after ;; a tick. on-tick ;; Integer Integer MouseEvent -> Void ;; EFFECT: updates this World<%> StatefulWorld<%> to the state that it should be in ;; after the given MouseEvent on-mouse ;; KeyEvent -> Void ;; EFFECT: updates this World<%> StatefulWorld<%> to the state that it should be in ;; after the given KeyEvent on-key ;; -> Scene ;; Returns a Scene depicting this world StatefulWorld<%> ;; on it. on-draw ;; -> Integer ;; RETURN: the x and y coordinates of the target target-x target-y ;; -> Boolean ;; Is the target selected? target-selected? ;; -> ListOfStatefulToy<%> get-toys )) ;; (define StatefulToy<%> (interface () ;; -> Void ;; EFFECT: updates this toy StatefulToy<%> to the state it should be in after a ;; tick. on-tick ;; Scene -> Scene ;; Returns a Scene like the given one, but with this toy StatefulToy<%> drawn ;; on it. add-to-scene ;; -> Int toy-x toy-y ;; -> ColorString ;; returns the current color of this toy StatefulToy<%> toy-color ))
You must provide the same functions and classes as in ps09, except that World%, SquareToy%, and CircleToy% must implement the interfaces above.
Turn in your solution as a file named "toys.rkt"
There are several places where information must be disseminated in this problem, either by pushing or pulling. Be prepared to identify these and to discuss your design decisions about each of them.
You must provide the same functions and classes as in the preceding question, except that the specifications for make-world and run are modified as follows following classes, functions, and interfaces. The differences are as follows:
StatefulWorld<%>
interface now has an additional
operation, target-color
StatefulToy<%>
interface now has additional operations,
on-mouse
and toy-selected?
StatefulToy<%>
interface no longer has an
on-tick
operation.make-world
, run
, and
make-square-toy
no longer have a speed argument Classes: World% -- a class that satisfies the StatefulWorld<%> interface (shown below). SquareToy% -- a class that satisfies the StatefulToy<%> interface CircleToy% Functions: make-world : -> World% GIVEN: no arguments RETURNS: A World% with no squares. run : PosNum -> World% GIVEN: a frame rate (in seconds/tick) EFFECT: creates and runs a world that runs at the given rate. RETURNS: the final world. make-square-toy : PosInt PosInt -> SquareToy% GIVEN: an x and a y position RETURNS: an object representing a square toy at the given position make-circle-toy : PosInt PosInt -> CircleToy% Interfaces: (define StatefulWorld<%> (interface () ;; -> Void ;; EFFECT: updates this StatefulWorld<%> to the ;; state that it should be in after a tick. on-tick ;; Integer Integer MouseEvent -> Void ;; EFFECT: updates this StatefulWorld<%> to the ;; state that it should be in after the given MouseEvent on-mouse ;; KeyEvent -> Void ;; EFFECT: updates this StatefulWorld<%> to the ;; state that it should be in after the given KeyEvent on-key ;; -> Scene ;; Returns a Scene depicting this StatefulWorld<%> on it. on-draw ;; -> Integer ;; RETURN: the x and y coordinates of the target target-x target-y ;; -> Boolean ;; Is the target selected? target-selected? ;; -> ColorString ;; color of the target target-color ;; -> ListOfStatefulToy<%> get-toys )) ;; (define StatefulToy<%> (interface () on-tick ;; Integer Integer MouseEvent -> Void ;; EFFECT: updates this StatefulToy<%> to the ;; state that it should be in after the given MouseEvent on-mouse ;; Scene -> Scene ;; Returns a Scene like the given one, but with this ;; StatefulToy<%> drawn on it. add-to-scene ;; -> Int toy-x toy-y ;; -> ColorString ;; returns the current color of this StatefulToy<%> toy-color Boolean ;; Is this StatefulToy<%> selected? toy-selected? ))
Turn in your solution as a file named "buddies.rkt".
For what it's worth, my solution was 562 lines exclusive of examples and tests. I debugged my solution using the testing techniques we talked about in the lessons. I wrote 135 lines of tests as I did this. I uncovered a few places where I had failed to correctly convert from functional to imperative form. For those, it was very helpful to have the original formulation using new Whatever% at hand in the comments, as I did in the slides. I also found one place where I had failed to maintain a key invariant. It would have been far more difficult to find that if I I had done the "usual" thing and simply inserted print statements and the like. --Prof. Wand
Qualification Files are at ps10-toys-qualification.rkt and ps10-buddies-qualification.rkt.
Last modified: Sat Nov 29 07:55:16 Eastern Standard Time 2014